﻿// --------------------------------
// <copyright file="BaseTest.cs" company="OpenTicket">
//     Microsoft Public License (Ms-PL)
// </copyright>
// <author>Glenn</author>
// ---------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTicket.Repositories;
using OpenTicket.Repositories.Entitymodel;
using OpenTicket.Services;
using StructureMap;

namespace OpenTicket.Tests
{
    /// <summary>
    /// Baseclass for all OpenTicket Tests
    /// </summary>
    public class BaseTest
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseTest"/> class.
        /// </summary>
        public BaseTest()
        {
            this.ConfigureDependencies();
            this.ProductService = ObjectFactory.GetInstance<IProductService>();
            this.OrderService = ObjectFactory.GetInstance<IOrderService>();
        }

        /// <summary>
        /// Gets or sets the product service.
        /// </summary>
        /// <value>The product service.</value>
        public IProductService ProductService { get; set; }

        /// <summary>
        /// Gets or sets the order service.
        /// </summary>
        /// <value>The order service.</value>
        public IOrderService OrderService { get; set; }

        /// <summary>
        /// Configures the dependencies.
        /// </summary>
        private void ConfigureDependencies()
        {
            ObjectFactory.Initialize(x =>
            {
                x.ForRequestedType<IProductService>().TheDefaultIsConcreteType<ProductService>().AlwaysUnique();
                x.ForRequestedType<IProductRepository>().TheDefaultIsConcreteType<EntityDataModelProductRepository>().AlwaysUnique();
                x.ForRequestedType<IOrderService>().TheDefaultIsConcreteType<OrderService>().AlwaysUnique();
                x.ForRequestedType<IOrderRepository>().TheDefaultIsConcreteType<EntityDataModelOrderRepository>().AlwaysUnique();
            });
        }
    }
}
